﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ArmoryData.Character;
using System.IO;
using Microsoft.WindowsCE.Forms;
using System.Net;
using Microsoft.WindowsMobile.Status;

namespace ArmoryViewerMobile
{
    public partial class Profile : Form
    {
        public CharacterInfo character;
        private SystemState OrientationWatcher;
            

        public Profile()
        {
            InitializeComponent();
            OrientationWatcher = new SystemState(SystemProperty.DisplayRotation);
            OrientationWatcher.Changed += new ChangeEventHandler(OrientationWatcher_Changed);
        }

        void OrientationWatcher_Changed(object sender, ChangeEventArgs args)
        {
            MessageBox.Show(args.NewValue.ToString());
        }

        public bool DownloadInfo(String name, String realm, String url)
        {
            character = new CharacterInfo(name, realm, new Uri(url));
            try
            {
                character.DownloadCharacterInfo();
                character.DownloadItems(false, "www");
                return true;
            }
            catch (CharacterNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Character Not Found", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                return false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message); // temp until error report coded
                return false;
            }
        }

        public void ShowInfo()
        {
            PortraitProfile.Character = this.character;
            PortraitProfile.LoadData();
            
        }

        private Image LoadImage(Uri uri)
        {
            WebResponse response = WebRequest.Create(uri).GetResponse();
            Stream img = response.GetResponseStream();
            Bitmap bmp = new Bitmap(img);
            response.Close();
            img.Close();
            return bmp;
        }

        private void Profile_Load(object sender, EventArgs e)
        {
            this.MinimizeBox = false;
        }
    }
}